<?php

class TixianAction extends Action {

    function index() {
        $tx = M("tixian");
        $user = M("users");
        $key = $this->_param("key");
        $this->assign("key", $key);
        if ($key) {
            $map = "userid like '%" . $key . "%' or alipay like '%" . $key . "%' or aliname like '%" . $key . "%' or money like '%" . $key . "%' or date like '%" . $key . "%'";
        } else {
            $map = "";
        }
        import('ORG.Util.Page'); // 导入分页类
        $count = $tx->where($map)->order("status asc,date desc")->count(); // 查询满足要求的总记录数
        $Page = new Page($count, 10);
        $show = $Page->show(); // 分页显示输出
        $list = $tx->where($map)->order("status asc,date desc")->limit($Page->firstRow . ',' . $Page->listRows)->select();
        $this->assign('page', $show); // 赋值分页输出
        $this->assign("list", $list);
        foreach ($list as $key => $value) {
            $li[$key + 1] = $user->where("id = " . $value['userid'])->getField("name");
        }
        $this->assign("li", $li);
        $this->display();
    }

    //确认
    function query() {
        $name = $this->_param("name");
        $id = $this->_param("id");
        $money = $this->_param("money");
        $ftime = $this->_param("ftime");
        $tx = M("tixian");
        
        //更改提现状态
        $data['status'] = 2;
        $tx->where("id = $id")->save($data);

        //扣除账户金额
        $mon = M("users");
        $mon->where("name = '" . $name . "'")->setDec("money", $money);
        
        //订单记录
        $ind = rand("100", "999");
        $bill = M("bill");
        $data1['name'] = $name;
        $data1['forname'] = "系统";
        $data1['indent'] = date("YmdHis") . $ind;
        $data1['money'] = $money;
        $data1['ftime'] = date("Y-m-d H:i:s");
        $data1['title'] = "提现";
        $bill->add($data1);
        
        //短信通知用户提现成功
        $user = M("users");
        $phone = $user->where("name = '" . $name . "'")->getField("phone"); //获取设计师手机号码
        $name = "wxr";
        $pwd = "wxr19890203";
        $msg = rawurlencode("您于".$ftime."所执行的提现申请已成功，所提现金额：".$money."元,已转到您的支付宝账中，详情请登录支付宝:https://auth.alipay.com/login/index.htm");
        $res = file_get_contents("http://www.gysoft.cn/smspost_utf8/send.aspx?username={$name}&password={$pwd}&mobile={$phone}&content={$msg}");
        
        //跳转页面
        if ($tx) {
            $this->redirect("/Tixian");
        }
    }

    //删除
    function del() {
//        $id = $this->_param("id");
    }

}

?>
